package ue.core;

import java.util.Random;

public class Util {
	
	private static final char[] vocals = new char[] { 'a', 'e', 'i', 'o', 'u', 'y' };
	private static final char[] consonants = new char[] { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 
														  'l', 'm', 'n', 'p', 'q', 'r', 's', 't',
														  'v', 'w', 'x', 'z' };
	
	public static String generateName(long seed, int length) {
		if(length < 0) return null;
		
		String tmp = "";
		int state = 0;
		Random random = new Random(seed);
		
		if(length == 0) {
			length = random.nextInt(4) + 4;
		}
		
		for(int i = 0; i < length; i++) {
			if(state == 0) {
				int rnd = random.nextInt(consonants.length);
				
				while (length - i <= 1 && consonants[rnd] == 'q') 
					rnd = random.nextInt(consonants.length);
				
				if(i == 0)
					tmp += Character.toUpperCase(consonants[rnd]);
				else
					tmp += consonants[rnd];
				state = random.nextInt(2) + 1;
			} else if(state == 1) {
				tmp += vocals[random.nextInt(vocals.length)];
				state = 0;
			} else if(state == 2) {
				if(tmp.length() > 1)
					tmp += tmp.charAt(tmp.length() - 1);
				state = 1;
				i--;
			}
		}
		
		return tmp;
	}
}
